
package com.hyst.seviceImpl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hyst.domain.Admin;
import com.hyst.repository.AdminMapper;
import com.hyst.service.AdminService;
import com.hyst.utils.StringUtils;
import com.hyst.utils.UuidTool;

/**
 * @Description:
 * @Date：2018年08月26日 @author： dy
 * @version ：1.0 1.[2018年08月26日]
 */
@Service
public class AdminServiceImpl implements AdminService {

	@Autowired
	private AdminMapper mapper;

	@Override
	public Page<Admin> list(final Admin admin) {
		final Page<Admin> page = PageHelper.startPage(admin.getPageNum(), admin.getPageSize());
		mapper.select(admin);
		return page;
	}

	@Override
	public Admin insert(final Admin admin) {
		admin.setUniqueid(UuidTool.randomUUID());
		mapper.insertSelective(admin);
		return admin;
	}

	@Override
	public Admin getByPriKey(final String uniqueid) {
		final Admin admin = mapper.selectByPrimaryKey(uniqueid);
		return admin;
	}

	@Override
	public Admin updateSelective(final Admin admin) {
		mapper.updateByPrimaryKeySelective(admin);
		return admin;
	}

	@Override
	public Admin update(final Admin admin) {
		mapper.updateByPrimaryKey(admin);
		return admin;
	}

	@Override
	public Admin delete(final String uniqueid) {
		mapper.deleteByPrimaryKey(uniqueid);
		return null;
	}

	// @Override
	// public boolean login(final String username, final String password) {
	// final Admin admin = new Admin();
	// admin.setUname(username);
	// admin.setPassword(StringUtils.getMD5(password));
	// final List<Admin> list = mapper.select(admin);
	//
	// // TODO Auto-generated method stub
	// if (list.size() > 0) {
	// return true;
	// } else {
	// return false;
	// }
	// }

	@Override
	public List<Map> getSelect2Data() {

		return mapper.getSelect2Data();
	}

	@Override
	public boolean login(final String username, final String password) {
		final Admin admin = new Admin();
		admin.setUname(username);
		admin.setPassword(StringUtils.getMD5(password));
		final List<Admin> list = mapper.select(admin);
		if (list.size() > 0) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public Admin getAdmin(String loginName) {
		return mapper.selectAdmin(loginName);
	}
}
